

package com.hexinfo.dmpro.common.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hexinfo.dmpro.common.annotation.AnonymousAccess;
import org.apache.ibatis.annotations.Param;
import org.springframework.http.ResponseEntity;
import com.hexinfo.dmpro.common.model.MessageCenter;
import com.hexinfo.dmpro.common.service.MessageCenterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * 消息中心表
 *
 * @author yemw
 * @date 2023-08-29 17:55:32
 */
@RestController
@AllArgsConstructor
@RequestMapping("/api/messagecenter" )
@Api(value = "messagecenter", tags = "消息中心表管理")
public class MessageCenterController {

    private final  MessageCenterService messageCenterService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param messageCenter 消息中心表
     * WrapperEnhancer.like(messageCenter); //自动拼接存在值sql的方法
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @AnonymousAccess
    public ResponseEntity<Object> getMessageCenterPage(Page page, MessageCenter messageCenter) {
        return ResponseEntity.ok(messageCenterService.queryList(page,messageCenter));
    }


    /**
     * 通过id查询消息中心表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public ResponseEntity<Object> getById(@PathVariable("id" ) String id) {
        return ResponseEntity.ok(messageCenterService.getById(id));
    }

    /**
     * 新增消息中心表
     * @param messageCenter 消息中心表
     * @return R
     */
    @ApiOperation(value = "新增消息中心表", notes = "新增消息中心表")
    @PostMapping
    @AnonymousAccess
    public ResponseEntity<Object> save(@RequestBody MessageCenter messageCenter) {
        return ResponseEntity.ok(messageCenterService.save(messageCenter));
    }

    /**
     * 修改消息中心表
     * @param messageCenter 消息中心表
     * @return R
     */
    @ApiOperation(value = "修改消息中心表", notes = "修改消息中心表")
    @PutMapping
    @AnonymousAccess
    public ResponseEntity<Object> updateById(@RequestBody MessageCenter messageCenter) {
        return ResponseEntity.ok(messageCenterService.updateById(messageCenter));
    }

    /**
     * 通过id删除消息中心表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除消息中心表", notes = "通过id删除消息中心表")
    @DeleteMapping("/{id}" )
    public ResponseEntity<Object> removeById(@PathVariable String id) {
        return ResponseEntity.ok(messageCenterService.removeById(id));
    }

    /**
     * 下载日志信息
     */
    @ApiOperation(value = "下载日志信息", notes = "下载日志信息")
    @GetMapping("/downLoadLog" )
    @AnonymousAccess
    public void downLoadLog(HttpServletRequest request, HttpServletResponse response,@Param("logPath") String logPath) throws IOException {
        messageCenterService.downLoadLog(request,response,logPath);
    }

    /**
     * 读取日志信息
     */
    @ApiOperation(value = "读取日志信息", notes = "读取日志信息")
    @GetMapping("/readLoadLog" )
    @AnonymousAccess
    public ResponseEntity<Object> readLoadLog(@Param("logPath") String logPath) {
          return ResponseEntity.ok(messageCenterService.readLoadLog(logPath));
    }
}

